<?php
/**
 * Joomla! 1.5 component ArticleCashRewards
 *
 * @version $Id: install.articlecashrewards.php 2009-05-10 01:47:01 svn $
 * @author Maverick
 * @package Joomla
 * @subpackage ArticleCashRewards
 * @license GNU/GPL
 *
 * Review and approve the articles and assign points and cash rewards.
 * Users can see their articles and the points/cash rewards assigned in the front-end module.
 *
 * This component file was created using the Joomla Component Creator by Not Web Design
 * http://www.notwebdesign.com/joomla_component_creator/
 *
 */
defined('_JEXEC') or die('Restricted access');

defined('JPATH_BASE') or die();
global $mainframe;

$install = "";
$notcomplete = "";

// publish plugin
$db	=& JFactory::getDBO();

$link = 'index.php?option=com_config&amp;controller=component&amp;component=com_articlecashrewards&amp;path=';
$rel  = 'rel="{handler: \'iframe\', size: {x: 580, y: 490}}"';
$class = 'class="modal"';
$text = "Parameters";
$image = JURI::base(true)."/components/com_articlecashrewards/assets/images/icon-48-config.png";

$query = "ALTER TABLE `#__acr_content` MODIFY COLUMN `id` INTEGER UNSIGNED NOT NULL DEFAULT 0, DROP PRIMARY KEY, ADD PRIMARY KEY (`article_id`)";
$db->setQuery($query);
$db->query();
$query = "ALTER TABLE #__acr_content MODIFY COLUMN points INT(3) UNSIGNED DEFAULT 0";
$db->setQuery($query);
$db->query();
$query = "ALTER TABLE `#__acr_referrals` DROP INDEX `UNIQUE`, ADD UNIQUE INDEX `UNIQUE` USING BTREE(`level`, `referredby`)";
$db->setQuery($query);
$db->query();

$query = "ALTER TABLE `boddunan`.`jos_acr_users` 
    ADD COLUMN `articles_cash` DECIMAL(7,2) NOT NULL DEFAULT 0,
    ADD COLUMN `referrals_cash` DECIMAL(7,2) NOT NULL DEFAULT 0,
    ADD COLUMN `weblinks_cash` DECIMAL(7,2) NOT NULL DEFAULT 0;
    ADD COLUMN `awards_cash` DECIMAL(7,2) NOT NULL DEFAULT 0;
";

/*Default Configuration Properties */
$query = 'INSERT INTO `#__acr_config` (`config_name`, `config_value`) VALUES' .
    '("min_payment_threshold", "0"),' .
    '("default_payment_method", "Check"),' .
    '("default_review_status", "1"),' .
    '("enable_points", "1"),' .
    '("enable_weblinks", "1"),' .
    '("enable_referrals","1"),' .
    '("enable_misc_pay","1"),' .
    '("weblink_cash_credits", "0"),' .
    '("email_sender_address", "yourname@yourmail.com"),' .
    '("email_sender_name", "UPDATE WITH SENDER NAME"),' .
    '("email_sub_article_approved", " submitted on UPDATE WITH YOUR SITE NAME is approved"),' .
    '("email_body_article_approved", "One "),' .
    '("email_sub_article_rejected", " submitted on UPDATE WITH YOUR SITE NAME is rejected"),' .
    '("email_body_article_rejected", ""),' .
    '("jom_social_ratings", "5"),' .
    '("points_system", "ACR"),' .
    '("review_form_pos", "1"),' .
    '("referral_system", "AUP"),' .
    '("default_review_status", "1")';

$db->setQuery( $query );
if(!$db->query()){
    $install .= '<br>Problems occured while updating default configuration values. Please ignore this if they are already esists.';
    $install .= '<br>SQL Executed: <br>'. $query;
}
/* End of default configuration properties */

$install .= '<br><img src="images/tick.png" alt="" /> Database tables successfully upgraded.<br>';
$install .=  '<img src="images/tick.png" alt="" /> Installation finished.<br /> Please check configuration section once to verify the details.';
?>
<table width="100%" border="0">
<tr>
	<td>
	<code>
	<?php echo $install; ?>
	</code><br />
	<?php echo $sql; ?>
	</td>
</tr>
</table>